<admintpl file="header"/>
</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform"  action="{:U('Admin/AdminUser/editRolePost')}">                
         <div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 90px;">一、新闻业务</label>
         	</div>
    	</div>
    	<?php 
    		if($role_data['column_role_count'] > 0){
    	?>
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;">常规栏目：</label>
            <div class="span3" style="width:800px;">
            	<?php
            		foreach($role_data['column_role'] as $column_key=>$column_value){
            	?>
                <input name="column_checbox[]"   type="checkbox"   value="{$column_value.column_id}"  <?php if(in_array($column_value['column_id'],$admin_user_column_role_data)) echo 'checked="checked" '?> />{$column_value.name}&nbsp;&nbsp;&nbsp;
                <?php
                	}
            	?>
            </div>
        </div>
    	<?php 
    		}
    	?>
    	
    	
    	<!-- 地区(开始) -->
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;">本地栏目</label>
            <div class="span3">
                <input type="text" style="width: 556px;" name="area" id="area" readonly="readonly" value="<?php echo $area_role_name_data ? implode(',',$area_role_name_data).',' : ''?>">
            </div>
        </div>
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
				<foreach name="established_area_data" key="key" item="value">
				<!-- 分组(开始) -->
				<div class="span3">
				<?php 
					switch($key){
						case 1:
							echo 'ABCDE';
							break;
						case 2:
							echo 'FGHIJ';
							break;
						case 3:
							echo 'KLMNO';
							break;
						case 4:
							echo 'PQRST';
							break;
						case 5:
							echo 'UVWXYZ';
							break;
					}
				?>
					<p></p>
					<!-- 拼音首字母(开始) -->
					<foreach name="value" key="key1" item="value1">
						<div class="span3">
						{$key1}&nbsp;&nbsp;
							<div class="span3">
							<foreach name="value1" key="key2" item="value2">
							<input name="area_checbox"  area_name="{$value2.name}" type="checkbox"   value="{$value2.area_id}"  <?php if(in_array($value2['area_id'],$area_role_id_data)) echo 'checked="checked" '?>/>{$value2.name}&nbsp;&nbsp;&nbsp;
							</foreach>
							</div>
						</div>
					</foreach>
					<!-- 拼音首字母(结束) -->
				</div>
				<!-- 分组(结束) -->
				</foreach>
            </div>
        </div>
    	<!-- 地区(结束) -->
    	
    	
    	<?php 
    		if($role_data['sys_menu_role_count'] > 0){
    	?>            
     	<div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 100px;"></label>
				<div class="span3" style="width:800px;">二、其他业务：
					<?php
	            		foreach($role_data['sys_menu_role'] as $sys_menu_key=>$sys_menu_value){
            		?>
	                	<input name="sys_menu_checbox[]"   type="checkbox"   value="{$sys_menu_value.menu_id}"  <?php if(in_array($sys_menu_value['menu_id'],$admin_user_sys_menu_role_data)) echo 'checked="checked" '?> />{$sys_menu_value.name}&nbsp;&nbsp;&nbsp;
	                <?php
	                	}
            		?>
				</div>
         	</div>
    	</div>
		<?php
			}
		?>
        
        <input type="hidden" name="admin_id" id="admin_id" value="<?php echo $admin_id;?>">
		<input type="hidden" name="area_hidden_ids" id="area_hidden_ids" value="<?php echo $area_role_id_data ? implode(',',$area_role_id_data).',' : ''?>">
        <div class="form-actions" style="padding-left:260px;">
            <a class="btn btn-primary" id="ajaxform">提 交</a>
            &nbsp;&nbsp;<a class="btn" id="ajaxback">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){
	$("[name='area_checbox']").click(function(){
		var area_id = $(this).val();
		var area_name = $(this).attr('area_name');
		
		var area_hidden_ids = $("#area_hidden_ids").val();
		var area_values = $("#area").val();
		
		var ids_arr = area_hidden_ids.split(",");          
		var values_arr = area_values.split(",");   
		
		if(ids_arr.indexOf(area_id) == '-1'){
			area_hidden_ids+=area_id+',';
			area_values+=area_name+',';
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==area_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			area_hidden_ids = ids_arr.join(",");
			area_values = values_arr.join(",");
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}
	})
})

// ajax 提交表单
$(document).ready(function(){
    $("#ajaxform").click(function(){    // 提交按钮触发事件
    	//获取新闻业务和其他业务的选中值
    	var boxes = $("[name='column_checbox[]']");
    	var boxes1 = $("[name='sys_menu_checbox[]']");
        var column_checbox = []
        var sys_menu_checbox = []
        for(i=0;i<boxes.length;i++){
            if(boxes[i].checked == true){
            	column_checbox.push(boxes[i].value);
            }
        }
        for(i=0;i<boxes1.length;i++){
            if(boxes1[i].checked == true){
            	sys_menu_checbox.push(boxes1[i].value);
            }
        }

        var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
        var admin_id = $("#admin_id").val();
        var area_hidden_ids = $("#area_hidden_ids").val();

        $.post(tourl,{
        	column_checbox:column_checbox,
        	sys_menu_checbox:sys_menu_checbox,
        	area_hidden_ids:area_hidden_ids,
        	admin_id:admin_id},function(result){
        	if(result == '1'){
        		var msg = '编辑成功';
        	}else{
        		var msg = '编辑失败';
        	}
        	
    		parent.layer.msg(msg,{time:2000},1,function(a){
        		
    		});
    		setTimeout(function(){
    			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    			parent.layer.close(index);
    		}, 1000);
          });
    });
    $("#ajaxback").click(function(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
    });
});
</script>
</body>
</html>